const equals = function(a, b) {
    if (isArray(a) && isArray(b)) {
        if (a.length !== b.length) {
            return false
        }
        for (let i = 0; i < a.length; i++) {
            if (!equals(a[i], b[i])) {
                return false
            }
        }
        return true
    } else if (isObject(a) && isObject(b)) {
        let keysA = Object.keys(a)
        let keysB = Object.keys(b)
        if (keysA.length !== keysB.length) {
            return false
        }
        for (let i = 0; i < keysA.length; i++) {
            let k = keysA[i]
            if (!equals(a[k], b[k])) {
                return false
            }
        }
        return true
    } else {
        return a === b
    }
}
const isArray = Array.isArray.bind(Array)

const isObject = o => Object.prototype.toString.call(o) === '[object Object]'
const log = console.log.bind(console)

const isDigit = function(c) {
    const alphabet = '-.0123456789'
    return alphabet.includes(c)
}
const isSpace = function(c) {
    const spaces = ' \n\t'
    return spaces.includes(c)
}
const isAuto = function(c) {
    const autos = '{}[]:,'
    return autos.includes(c)
}
const isKeywordChar = (char) => {
    return 'abcdefghijklmnopqrstuvwxyz'.includes(char)
}

const ensure = (condition, message) => {
    if (!condition) {
        log('**** 测试失败,', message)
    } else {
        log('|||| 测试成功', message)
    }
}

module.exports = {
    log,
    equals,
    isDigit,
    isSpace,
    isAuto,
    isKeywordChar,
    ensure
}